package com.xerokhan.diary.util;

import java.util.ArrayList;
import java.util.Date;
import java.util.Random;

public class GenerateMoneyData {

	public static String[] expense = { "Advertising", "Apartment maintenance", "Auto", "Auto Rental", "Bank Fee", "Business", "Cash", "Charity/Donations",
			"Childcare/Daycare", "Clothing", "Commissions and Fees", "Cook", "Credit Card", "Department-store", "Washerman", "Dining", "Doctor consultation",
			"Education", "Electricity Bill", "Entertainment", "Fruits", "Fuel", "Gifts", "Groceries", "Health and Fitness", "Home Repair", "Household",
			"Insurance", "Interest", "Jewellery", "Landline bill", "Legal and Professional Fees", "Loan", "Lodging", "Maid Servant", "Materials and Supplies",
			"Meals and Entertainment", "Medical", "Medicines", "Milkman", "Mobile phone bill", "Mortgage", "My Kids", "My Pets", "Newspaper/Magazines",
			"Office Supplies", "Other Expense", "Phone", "Property Tax", "Rent", "Repair and Maintenance", "School van", "Shipping", "Tax and Licenses",
			"Tax Payment", "Transfer Out", "Travel-Airline", "Travel-Hotel", "Vacation/Travel", "Vegetables", "Veterinary Services", "Water bill",
			"Misc. Expense" };

	/**
	 * 
	 */

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		createExpenditure();
	}

	public static void createGoal() {
		// income,
		// item_category_id,
		// amount_expected,
		// amount_spent,
		// month,
		// year,
		// time,
		// user_id,

		// ten goals
		for (int i = 1; i <= 9; i++) {
			int user_id = 1;
			int year = 2012;
			int month = i;
			int income = 50000 + Math.abs(new Random().nextInt() % 10000);
			int inc = income;
			ArrayList<Integer> item_category_id_list = getDistinctRandomInt(expense.length, 10);
			for (int j = 0; j < 10; j++) {
				if (income <= 0)
					break;
				long time = new Date().getTime();
				int item_category_id = item_category_id_list.get(j);
				int amount_expected = Math.abs(new Random().nextInt() % income) + 10;
				income -= amount_expected;

				System.out.println("insert into monthly_goal(income,item_category_id,amount_expected,month,year,timestamp,user_id)" + " values(" + inc + ","
						+ item_category_id + "," + amount_expected + "," + month + "," + year + ",'" + time + "'," + user_id + ");");
			}
		}
	}

	public static void createCategory() {
		for (int i = 0; i < expense.length; i++) {
			System.out.println("insert into expenditure_category(name) values('" + expense[i] + "');");
		}
	}

	public static void createExpenditure() {
		// expenditure_id INT NOT NULL AUTO_INCREMENT,
		// item_name VARCHAR(100) NULL ,
		// item_category_id int NULL ,
		// amount_spent DECIMAL(20) NULL ,
		//
		// user_id INT NULL ,
		// month int NULL,
		// year int NULL,
		//
		// total_days int null,
		// total_months int null,
		// total_years int null,
		//
		// timestamp varchar(20) null,
		for (int i = 1; i <= 9; i++) {
			int user_id = 1;
			int year = 2012;
			int month = i;
			ArrayList<Integer> item_category_id_list = getDistinctRandomInt(expense.length, 30);
			for (int j = 0; j < 10; j++) {
				Date d = new Date(year, i - 1, 2);
				long timestamp = d.getTime();
				int amount_expected = Math.abs(new Random().nextInt() % 25000) + 10;
				int item_category_id = item_category_id_list.get(j) + 1;
				long total_days = DateUtil.getDaysFrom1900(d);
				long total_months = DateUtil.getMonthsFrom1900(d);
				long total_years = DateUtil.getYearsFrom1900(d);

				System.out.println("insert into expenditure(item_category_id,amount_spent,total_days, total_months, total_years, timestamp,user_id,month,year)"
						+ " values(" + item_category_id + "," + amount_expected + "," + total_days + "," + total_months + "," + total_years + ",'" + timestamp
						+ "'," + user_id + "," + month + "," + year + ");");
			}
		}

	}

	public static ArrayList<Integer> getDistinctRandomInt(long seed, int count) {
		ArrayList<Integer> list = new ArrayList<Integer>();
		Random r = new Random();
		for (int i = 0; i < count; i++) {

			int n = (int) Math.abs((r.nextInt() % seed));
			while (list.contains(n)) {
				n = (int) Math.abs((r.nextInt() % seed));
			}
			list.add(n);
		}
		return list;
	}
}
